<?php
/*
 * Copyright 2009 Eat Local Food, LLC
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */

define('IN_ADMIN_COMPONENT_CONTROLLER', 'true');

function tep_get_system_information() {
	global $HTTP_SERVER_VARS;

	list($system, $host, $kernel) = preg_split('/[\s,]+/', @exec('uname -a'), 5);

	return array(
                 'system' => $system,
                 'kernel' => $kernel,
                 'host' => $host,
                 'ip' => gethostbyname($host),
                 'uptime' => @exec('uptime'),
                 'http_server' => $HTTP_SERVER_VARS['SERVER_SOFTWARE'],
                 'php' => PHP_VERSION,
                 'zend' => (function_exists('zend_version') ? zend_version() : ''),
                 'db_server' => DB_SERVER,
                 'db_ip' => gethostbyname(DB_SERVER),
                 'db_version' => 'MySQL ' . (function_exists('mysql_get_server_info') ? mysql_get_server_info() : ''));
}

class ServerInfoComponent
{
	function ServerInfoComponent()
	{
	}

	function action(&$params, $action='query')
	{
		return $this->query($params);
	}

	function query(&$params)
	{

		$system = tep_get_system_information();
?>
<html><body>
  <style type="text/css">
    body, td, th {font-family: sans-serif; font-size: 10px;}
    .p {text-align: left;}
    .e {background-color: #ccccff; font-weight: bold;}
    .h {background-color: #9999cc; font-weight: bold;}
    .v {background-color: #cccccc;}
    i {color: #666666;}
    hr {display: none;}
  </style>

  <table border="0" cellspacing="0" cellpadding="3">
    <tr>
      <td class="smallText"><b><?php echo TITLE_SERVER_HOST; ?></b></td>
      <td class="smallText"><?php echo $system['host'] . ' (' . $system['ip'] . ')'; ?></td>
      <td class="smallText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><?php echo TITLE_DATABASE_HOST; ?></b></td>
      <td class="smallText"><?php echo $system['db_server'] . ' (' . $system['db_ip'] . ')'; ?></td>
    </tr>
    <tr>
      <td class="smallText"><b><?php echo TITLE_SERVER_OS; ?></b></td>
      <td class="smallText"><?php echo $system['system'] . ' ' . $system['kernel']; ?></td>
      <td class="smallText">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><?php echo TITLE_DATABASE; ?></b></td>
      <td class="smallText"><?php echo $system['db_version']; ?></td>
    </tr>
    <tr>
      <td class="smallText"><b><?php echo TITLE_SERVER_UP_TIME; ?></b></td>
      <td colspan="3" class="smallText"><?php echo $system['uptime']; ?></td>
    </tr>
    <tr>
      <td class="smallText"><b><?php echo TITLE_HTTP_SERVER; ?></b></td>
      <td colspan="3" class="smallText"><?php echo $system['http_server']; ?></td>
    </tr>
    <tr>
      <td class="smallText"><b><?php echo TITLE_PHP_VERSION; ?></b></td>
      <td colspan="3" class="smallText"><?php echo $system['php'] . ' (' . TITLE_ZEND_VERSION . ' ' . $system['zend'] . ')'; ?></td>
    </tr>
  </table>
  <br/>

<?php
		ob_start();
		phpinfo();
		$phpinfo = ob_get_contents();
		ob_end_clean();
		$phpinfo = str_replace('border: 1px', '', $phpinfo);
		preg_match('/<body>(.*)<\/body>/xsmi', $phpinfo, $regs);
		echo $regs[1];
	}
}
?>
</body></html>
